var PROJECT_NAME="app-yunhetong-center";
var zntgDomain='';
$(document).ready(function(){
    // 初始化内容


});
/**
 *管理人信息相关操作
 * @author xianyun
 */
/**
 * 管理人新增
 * @param custNm 企业名称
 * @param certTyp 证件类型;前台获取,存类型ID
 * @param certNo 认证号码
 * @param mobileNo 手机号
 * @param crmMagerId CRM对应管理人ID
 * @param caCustId 客户ID
 * @param idenUser 认证人ID
 */
function addMagerIndcInfo(custNm,certTyp,certNo,mobileNo,crmMagerId,caCustId,idenUser){
    var url=getProjectApiUrl()+"/api/v1/magerIndcInfo/add";
    var param={"custNm":custNm,"certTyp":certTyp,"certNo":certNo,"mobileNo":mobileNo,"crmMagerId":crmMagerId,"caCustId":caCustId,"idenUser":idenUser};
    var result=sendMyAjaxPost(url,param);
    if(result.code==0){
        layer.alert("认证成功", {
            icon: 6,
            skin: 'layer-ext-moon' //该皮肤由layer.seaning.com友情扩展。关于皮肤的扩展规则，去这里查阅
        },function () {
            parent.layer.closeAll();
            if($("#refresh")){
                $("#refresh").click();
            }
            if( $("#refresh",window.parent.document)){
                $("#refresh",window.parent.document).click();
            }


        })
    }else{
        messageInfo(result.msg);
        return false;
    }
}
/**
 * 模板的新增
 * @param type
 * @param caCustId
 */
function addTemplate(crmMagerId,type,caCustId,fileId,fileName,fileUrl){
    var url=getProjectApiUrl()+"/api/v1/magerIndcInfo/template/save";
    console.log("新增模板地址url============"+url);
    var param={"crmMagerId":crmMagerId,"type":type,"caCustId":caCustId,"operatorId":operatorId,"fileId":fileId,"fileName":fileName,"fileUrl":fileUrl};
    console.log("参数======"+JSON.stringify(param));
    var result=sendMyAjaxPost(url,param);
    console.log("返回结果========="+JSON.stringify(result));
    if(result.code==0){
        layer.alert("操作成功", {
            icon: 6,
            skin: 'layer-ext-moon' //该皮肤由layer.seaning.com友情扩展。关于皮肤的扩展规则，去这里查阅
        },function () {
            //location.reload();
            $("#refresh").click();

        })
    }else{
        messageInfo(result.msg);
        return false;
    }
}
/**
 * 模板的删除
 * @param type
 * @param caCustId
 */
function deleteTemplate(type,caCustId){
    var url=getProjectApiUrl()+"/api/v1/magerIndcInfo/template/save";
    var param={"type":type,"caCustId":caCustId,"operatorId":operatorId};
    layer.confirm('确定要删除吗？', {
         btn: ['确定','取消'] //按钮
    }, function(){
        var result=sendMyAjaxPost(url,param);
        if(result.code==0){
            layer.alert("操作成功", {
                icon: 6,
                skin: 'layer-ext-moon' //该皮肤由layer.seaning.com友情扩展。关于皮肤的扩展规则，去这里查阅
            },function () {
                //window.location.reload();
                $("#refresh").click();

            })
        }else{
            messageErrorInfo(result.msg);
            return false;
        }
        }, function(){
           //取消
        });
}

/**
 * 获取项目接口地址
 * @returns {string}
 */
function getProjectApiUrl(){
    //使用 window.locaion.href 获得项目的根路径
    var curWwwPath = window.document.location.href;
    //获得主机地址之后 的目录
    var pathname= window.document.location.pathname;
    var pos = curWwwPath.indexOf(pathname);
    //获得主机地址
    var localhostPath = curWwwPath .substring(0,pos);
    return localhostPath+"/"+PROJECT_NAME;
}

/**
 * 自定义弹出框，5是失败，6是成功
 * @param msg
 */
function messageInfo(msg){
    layer.alert(msg, {
        icon: 6,
        skin: 'layer-ext-moon' //该皮肤由layer.seaning.com友情扩展。关于皮肤的扩展规则，去这里查阅
    })
}
function messageErrorInfo(msg){
    layer.alert(msg, {
        icon: 5,
        skin: 'layer-ext-moon' //该皮肤由layer.seaning.com友情扩展。关于皮肤的扩展规则，去这里查阅
    })
}

/**
 * 获取秀实投资app后台当前登录的账号id
 * @author 贤云
 * @returns {string}
 */
function getCurrentLoginUser(){
    var currentLoginUserId="";
    //获取用户中心微服务
    var url=getProjectApiUrl()+"/api/v2/user/getDomain";
    var param={};
    var result=sendMyAjaxPost(url,param);
    zntgDomain=result.data;
    var url=zntgDomain+"/api/v2/user/getCurrentUser";
    var param={};
    var getCurrentLoginUserResult=sendMyAjaxPost(url,param);
    var code=getCurrentLoginUserResult.code;
    if(code=='1003'){
        //messageInfo("请先登录")
    }
    if(code=='0'){
        currentLoginUserId=getCurrentLoginUserResult.data;
    }
    return currentLoginUserId;
}